Skip to content

Update example for converting DLC project to benchmark (v2)#49

Merged
lochhh merged 24 commits into
mainfrom
update-dlc-to-coco-example-v2
May 26, 2026
Merged

Update example for converting DLC project to benchmark (v2)#49
lochhh merged 24 commits into
mainfrom
update-dlc-to-coco-example-v2

Conversation

@niksirbi
Copy link
Copy Markdown
Member

@niksirbi niksirbi commented May 12, 2026

Summary

Clean replacement for #40 (Frankenstein branch). Starts fresh from main, builds on top of the now-merged #45 (predictions_to_poseinterface), and adds the gallery example plus supporting utilities and a lightweight test fixture.

The example walks through the following workflow:

DLC_to_poseinterface_worklow

Warning

This example specifically documents the DLC-to-poseinterface conversion process. Trying it on other pose estimation software is encouraged, but adaptations will be needed, and the underlying functions are not yet tested on non-DLC inputs. Other source software will be tackled in future PRs.

What's included

  • frames_to_poseinterface: copies and renames frame images to match the filenames in a framelabels.json (unit tests included).
  • Lightweight DLC project fixture under tests/data/dlc/MouseTopDown-Loukia-2022-09-13/ : 2 sessions, short MP4 videos, placeholder PNG frames, annotation + prediction CSVs. Used by tests and the gallery example.
  • convert_dlc_to_benchmark sphinx-gallery example: replacing the old SWC-plusmaze_to_benchmark example. Runs end-to-end against the bundled fixture and demonstrates the full DLC → benchmark conversion (video, framelabels + frame copy, videolabels) followed by clip extraction.
  • tree utility: for displaying directory structures, used in the example (unit tests included).
  • movement pin bumped to >=0.16.0 (the version introducing the automatic source-software inference, which predictions_to_poseinterface now relies on).
  • Docs updates:
    • sphinx-gallery execution enabled in conf.py
    • API index entries for tree, frames_to_poseinterface, and predictions_to_poseinterface.
    • Docs dependencies: jupyter, matplotlib.

Supersedes

How was this tested

I used a variant of this example locally to convert 2 sessions from a 'real' dataset (not just the fixture) and inspect the resulting .json files. The real dataset was structured similarly to the fixture included here.

Checklist

  • All unit tests pass locally
  • Pre-commit run
  • Sphinx-gallery example runs end-to-end (python examples/convert_dlc_to_benchmark.py)
  • Docs build successfully (make clean html from docs/)
  • CI passes

How to review

I recommend primarily reviewing the built example end-to-end, and then diving into the newly introduced tree/frames_to_poseinterface functions if/when necessary.

niksirbi and others added 10 commits May 18, 2026 16:19
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add frames_to_poseinterface utility to copy and rename frame images
according to filenames in a COCO JSON file. Also fix the output
filename of predictions_to_poseinterface to use _cliplabels.json
suffix matching the naming convention.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a minimal DLC project under tests/data/dlc/ with 2 sessions,
each containing a small (100 frames) video, placeholder PNGs, and
annotation/prediction CSVs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace SWC-plusmaze_to_benchmark example with a new end-to-end
example showing how to convert a DLC project to the poseinterface
benchmark dataset format. Update sphinx-gallery config to execute
examples, add API entries for new functions, and add jupyter and
matplotlib dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@niksirbi niksirbi force-pushed the update-dlc-to-coco-example-v2 branch from 99eed8a to 6cfef6b Compare May 18, 2026 15:32
@niksirbi niksirbi marked this pull request as ready for review May 19, 2026 10:27
@niksirbi niksirbi requested a review from a team May 19, 2026 10:46
@lochhh lochhh requested review from lochhh and removed request for a team May 19, 2026 10:52
Copy link
Copy Markdown
Member

@lochhh lochhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @niksirbi !

I tried the example with a sample dlc project (that has annotations only) and it broke when it tries to find the predictions file. Otherwise the example works as expected. My suggestion is to skip the conversion(s) in the example if the expected files are not found.

It's very nice that we now have a sample DLC project in test data. I'm guessing the broken frame files are intentional, but it would be better to have actual frames, since this would allow us to have images with non-zero width and height in the COCO JSON files. As a follow-up PR, we should consider adding the generated benchmark dataset(s) as part of our test data. These could replace the current "reference dataset" Train/SWC-plusmaze/sub-M708149_ses-20200317/, giving us a more cohesive and internally consistent set of test fixtures (using the sample DLC project as test inputs and the reference dataset as expected outputs) - our current test data comes from a mix of sample inputs/outputs across different projects, along with multiple ad‑hoc fixtures.

Comment thread poseinterface/io.py Outdated
Comment thread poseinterface/io.py
Comment thread poseinterface/io.py Outdated
Comment thread pyproject.toml
Comment thread examples/convert_dlc_to_benchmark.py Outdated
Comment thread examples/convert_dlc_to_benchmark.py Outdated
Comment thread tests/test_unit/test_io.py
Comment thread tests/test_unit/test_utils.py
Comment thread tests/test_unit/test_utils.py Outdated
niksirbi and others added 6 commits May 26, 2026 14:39
Co-authored-by: Chang Huan Lo <changhuanlo@yahoo.com>
Co-authored-by: Chang Huan Lo <changhuanlo@yahoo.com>
Co-authored-by: Chang Huan Lo <changhuanlo@yahoo.com>
Add `import warnings` to io.py (needed after review suggestion
introduced `warnings.warn`), update error message match in existing
test, and add a new test for the partial-match warning path.
Includes minor formatting fixes from ruff-format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Chang Huan Lo <changhuanlo@yahoo.com>
niksirbi and others added 2 commits May 26, 2026 15:29
The write_text() return value (byte count) was rendered as cell
output by sphinx-gallery. Use capture_repr = () to suppress it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Renders `Path | str` instead of `Union[Path, str]` in API docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@niksirbi
Copy link
Copy Markdown
Member Author

Thanks for the review @lochhh and for re-organising the example in a more logical way.

I've accepted your suggestions, except for the ones about test fixtures (we'll tackle these separately as part of #53).

@niksirbi niksirbi requested a review from lochhh May 26, 2026 15:38
Copy link
Copy Markdown
Member

@lochhh lochhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🚀

@lochhh lochhh merged commit f3a141c into main May 26, 2026
24 checks passed
@lochhh lochhh deleted the update-dlc-to-coco-example-v2 branch May 26, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants